//
//  NSMutableAttributedString+Attributed.m
//  MGPublic
//
//  Created by lhongl on 2025/10/28.
//

#import "NSMutableAttributedString+Attributed.h"

@implementation NSMutableAttributedString (Attributed)
/// 文字大小
- (NSMutableAttributedString *(^)(UIFont *font))font {
    return ^(UIFont *font){
        [self addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, self.string.length)];
        return self;
    };
}

/// 获取文字大小
- (UIFont * _Nullable (^)(void))getFont {
    return ^(void){
        NSDictionary *attx = [self attributesAtIndex:0 effectiveRange:NULL];
        return attx[NSFontAttributeName];
    };
}

/// 文字颜色
- (NSMutableAttributedString *(^)(UIColor *color))textColor {
    return ^(UIColor *color){
        [self addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(0, self.string.length)];
        return self;
    };
}

/// 获取文字验收
- (UIColor * _Nullable (^)(void))getTextColor {
    return ^(void){
        NSDictionary *attx = [self attributesAtIndex:0 effectiveRange:NULL];
        return attx[NSForegroundColorAttributeName];
    };
}

/// link
- (NSMutableAttributedString *(^)(NSString *link))link {
    return ^(NSString *link){
        [self addAttribute:NSLinkAttributeName value:link range:NSMakeRange(0, self.string.length)];
        return self;
    };
}

/// 背景色
- (NSMutableAttributedString *(^)(UIColor *color))backColor {
    return ^(UIColor *color){
        [self addAttribute:NSBackgroundColorAttributeName value:color range:NSMakeRange(0, self.string.length)];
        return self;
    };
}

/// 下划线
- (NSMutableAttributedString *(^)(BOOL line))underline {
    return ^(BOOL line){
        if (line) {
            [self addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:NSMakeRange(0, self.string.length)];
        }else {
            [self removeAttribute:NSUnderlineStyleAttributeName range:NSMakeRange(0, self.string.length)];
        }
        return self;
    };
}

/// 下划线颜色
- (NSMutableAttributedString *(^)(UIColor *color))underlineColor {
    return ^(UIColor *color){
        [self addAttribute:NSUnderlineColorAttributeName value:color range:NSMakeRange(0, self.string.length)];
        return self;
    };
}

/// 删除线
- (NSMutableAttributedString *(^)(BOOL line))through {
    return ^(BOOL line){
        if (line) {
            [self addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleSingle) range:NSMakeRange(0, self.string.length)];
        }else {
            [self removeAttribute:NSStrikethroughStyleAttributeName range:NSMakeRange(0, self.string.length)];
        }
        return self;
    };
}

/// 删除线颜色
- (NSMutableAttributedString *(^)(UIColor *color))throughColor {
    return ^(UIColor *color){
        [self addAttribute:NSStrikethroughColorAttributeName value:color range:NSMakeRange(0, self.string.length)];
        return self;
    };
}


@end
